<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>开通会员</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        h2 {
            text-align: center;
            margin-bottom: 30px;
        }

        .membox {
            width: 887px;
            margin: 50px auto;
        }

        .membox ul {
            overflow: hidden;
        }

        .membox ul li {
            float: left;
            width: 120px;
            height: 80px;
            border: 1px solid #dbdbdb;
            border-radius: 4px;
            font-size: 14px;
            cursor: pointer;
            margin-right: 30px;
        }

        .membox ul .on {
            border: 1px solid #F5602A;
            background: url(../static/img/select2.png) no-repeat right bottom;
        }

        .membox ul li:last-child {
            margin-right: 0;
        }

        .membox ul li p {
            color: #888;
            text-align: center;
            margin-top: 5px;
        }

        .membox ul li p:last-child {
            color: #f5602a;
        }

        .membox ul li p:last-child span {
            color: #f5602a;
            font-size: 18px;
            margin: 0 3px;
        }

        .membox ul li p:last-child i {
            font-style: initial;
            color: #666;
        }

        .memBtn {
            height: 44px;
            line-height: 44px;
            background-color: #ff8e01;
            color: #fff;
            text-align: center;
            border-radius: 4px;
            width: 160px;
            font-size: 18px;
            margin: 0 auto;
            cursor: pointer;
        }

    </style>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- import Vue before Element -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

</head>
<body>
<div id="app">
    <div class="membox">
        <h2>开通会员</h2>
        <ul>
            <li v-for="(member) in memberList" @click="choose(member)" v-bind:class="isOn">
                <p >
                    <span>￥{{member.amount}}</span>
                    <br/>
                    <span>{{member.description}}</span>
                </p>
            </li>

        </ul>
    </div>

    		<div class="memBtn" @click="recharge">确认开通</div>
    <el-button type="primary" icon="el-icon-search" @click="toRecord">查询消费记录</el-button>
    <el-button type="primary" icon="el-icon-search" @click="toUser">查询用户信息</el-button>
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    // $(function(){
    // 	$('.membox ul li').click(function(){
    // 		$(this).addClass('on').siblings().removeClass('on')
    // 	})
    // })
    new Vue({
        el: '#app',
        data() {
            return{
            memberList: [],
            memberId: "",
            isOn:"",
            description:""
        }
        },
        methods: {
            choose: function(member)  {
                this.memberId = member.id
                this.isOn = "on"
                this.description = member.description
                alert("您选择充值"+member.description)
            },
            recharge: function () {
                if(confirm("您确认充值"+this.description) == true){
                    axios.get('/api/member/recharge', {
                        params: {
                            "memberId": this.memberId,
                            "userId": "1"
                        }
                    }).then(res => {
                        if(res.data.success){
                            alert("充值成功")
                        }
                        else {
                            alert(res.data.data)
                        }
                    })
                }
            },
            toRecord: function (){
                window.location.href='http://127.0.0.1:8080/api/record/index';
            },
            toUser: function (){
                window.location.href='http://127.0.0.1:8080/api/user/index';
            }
        },

        beforeCreate() {
            axios.get('/api/member/getMemberList')
                .then(response => {
                    this.memberList = response.data.data;
                })
                .catch(error => {
                    console.log(error);
                });
        }
    })
</script>
</body>
</html>
